package com.auemall.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.auemall.service.PictureService;
import com.auemall.utils.JsonUtils;
import com.auemall.vo.UploadFileAndPictureRespVO;


@Controller
public class PictureController {

	@Autowired
	private PictureService pictureService;
	
	/**
	 * 
	 * @Title: pictureUpload 
	 * @Description: TODO(用编辑器上传图片【通用】)
	 * @param uploadFile
	 * @return String  
	 * @author WangChao
	 */
	@RequestMapping("/pic/upload")
	@ResponseBody
	public String pictureUpload(MultipartFile uploadFile) {
		
		Map<String,Object> result = pictureService.uploadPicture(uploadFile);
		//为了保证功能的兼容性，需要把Result转换成json格式的字符串。
		String json = JsonUtils.objectToJson(result);
		return json;
		
	}
	
	/**
	 * 
	 * @Title: UploadFile 
	 * @Description: TODO(示例，暂时未使用)
	 * @param request
	 * @param response void  
	 * @author WangChao
	 */
	@RequestMapping("/uploadfile")
    @ResponseBody
    public void UploadFile(HttpServletRequest request, HttpServletResponse response) {
        
       try {
           pictureService.UploadFile(request, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
       
    }
	
	/**
	 * 
	 * @Title: uploadFileAndPicture 
	 * @Description: TODO(商品发布时上传规格书)
	 * @param uploadFile
	 * @return UploadFileAndPictureRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/upload")
    @ResponseBody
    public UploadFileAndPictureRespVO uploadFileAndPicture(@RequestParam(value = "file_ggs") MultipartFile uploadFile) {
	    
	    return pictureService.uploadFileAndPicture(uploadFile);
    }
	
	/**
	 * 
	 * @Title: uploadCatPicture 
	 * @Description: TODO(新增商品分类时上传分类图标)
	 * @param uploadFile
	 * @return UploadFileAndPictureRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/uploadcatpic")
    @ResponseBody
    public UploadFileAndPictureRespVO uploadCatPicture(@RequestParam(value = "file_fltb") MultipartFile uploadFile) {
        
        return pictureService.uploadFileAndPicture(uploadFile);
    }
	
	/**
	 * 
	 * @Title: uploadCatGgs 
	 * @Description: TODO(新增商品分类时上传规格书)
	 * @param uploadFile
	 * @return UploadFileAndPictureRespVO  
	 * @author WangChao
	 */
	@RequestMapping("/uploadcatggs")
    @ResponseBody
    public UploadFileAndPictureRespVO uploadCatGgs(@RequestParam(value = "file_cat_ggs") MultipartFile uploadFile) {
        
        return pictureService.uploadFileAndPicture(uploadFile);
    }
	
	
	
}
